package com.wclass.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.google.common.collect.Maps;
import com.wclass.entity.BaseHelpCenter;
import com.wclass.entity.BaseHelpType;
import com.wclass.mapper.BaseHelpCenterMapper;
import com.wclass.mapper.BaseHelpTypeMapper;
import com.wclass.service.IBaseHelpTypeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 帮助中心类型 服务实现类
 * </p>
 *
 * @author SEN
 * @since 2019-02-13
 */
@Service
public class BaseHelpTypeServiceImpl extends ServiceImpl<BaseHelpTypeMapper, BaseHelpType> implements IBaseHelpTypeService {

    @Autowired
    private BaseHelpCenterMapper helpCenterMapper;

    @Override
    public List<BaseHelpType> selectListByAffiliation(Integer affiliation) {
        EntityWrapper<BaseHelpType> ew = new EntityWrapper<>();
        ew.eq("affiliation", affiliation);
        List<BaseHelpType> list = baseMapper.selectList(ew);
        for (BaseHelpType info : list) {
            EntityWrapper<BaseHelpCenter> center_ew = new EntityWrapper<>();
            center_ew.eq("type_id", info.getId());
            List<BaseHelpCenter> centers = helpCenterMapper.selectList(center_ew);
            for (BaseHelpCenter center : centers) {
                Map<String, Object> map = Maps.newHashMap();
                map.put("id", center.getId());
                map.put("title", center.getTitle());
                info.getList().add(map);
            }
        }
        return list;
    }
}
